class HueCue(object):
    def __init__(self, idx=0, func=None, posargs=[], kwargs={}):
        self.idx = idx
        self.func = func
        self.posargs = posargs
        self.kwargs = kwargs

    def __call__(self):
        if not hasattr(self.func, '__call__'):
            raise Exception("%s has no function to call!" % str(self))

        self.func(*self.posargs, **self.kwargs)

    def __str__(self):
        s = "----CUE AT %d----:\n"\
            "FUNCTION: %s\n"\
            "POSARGS:  %s\n"\
            "KWARGS:   %s\n" %\
            (self.idx, str(self.func), str(self.posargs), str(self.kwargs))

        return s

    def adjustForTimeDilation(self, timeDilation=1.0):
        timeDilation = float(timeDilation)
        self.idx /= timeDilation
        self.idx = int(self.idx)

        datadict = {}

        # try to find a datadict in the positional arguments
        for arg in self.posargs:
            if isinstance(arg, tuple):
                if len(arg) > 1 and isinstance(arg[1], dict):
                    datadict = arg[1]
                    break

        # failing that, look in the keyword arguments
        if not datadict and 'datadict' in self.kwargs:
            datadict = self.kwargs['datadict']

        if 'transitiontime' in datadict.keys():
            datadict['transitiontime'] /= timeDilation
            datadict['transitiontime'] = int( datadict['transitiontime'] )
